
using System;
using System.Collections.Generic;
using OrdersManager.Module;
using OrdersManager.Module.BusinessEntities;
using OrdersManager.Module.Constants;
using OrdersManager.Module.Services;

namespace OrdersManager.Module.Tests.Mocks
{
	public class MockOrderService : IOrderService
	{
		private OrderCollection _ordersRetrieved ;
        private Order _orderProcessed;
        private OrderStatus _selectedStatus = OrderStatus.Initial;
        private bool _isNewOrder;

        public Order OrderProcessed
        {
            get 
            { 
                return _orderProcessed; 
            }
            set 
            { 
                _orderProcessed = value; 
            }
        }

        public OrderStatus SelectedStatus
        {
            get 
            { 
                return _selectedStatus; 
            }
            set 
            { 
                _selectedStatus = value; 
            }
        }

        public bool IsNewOrder
        {
            get 
            { 
                return _isNewOrder; 
            }
            set 
            { 
                _isNewOrder = value; 
            }
        }

		public void SaveOrder(Order order)
		{
		}

		public void ShipOrder(Order order)
		{
		}

		public void ProcessOrder(Order order)
		{
			OrderProcessed = order;
		}

		public void CancelOrder(Order order)
		{
		}

		public Order GetOrderById(Guid orderId)
		{
			return null;
		}

		public OrderCollection GetOrdersByState(OrderStatus stateMode)
		{
			SelectedStatus = stateMode;
			_ordersRetrieved = new OrderCollection(new Order[] {new Order()});
			return _ordersRetrieved;
		}

		public ICollection<OrderStatus> GetOrderPossibleStates(Order order)
		{
            List<OrderStatus> states = new List<OrderStatus>();

            if (IsNewOrder)
                states.Add(OrderStatus.Initial);
            else
                switch (SelectedStatus)
                {
                    case OrderStatus.Initial:
                        states.Add(OrderStatus.Opened);
                        break;
                    case OrderStatus.Opened:
                        states.Add(OrderStatus.Opened);
                        states.Add(OrderStatus.Processed);
                        break;
                    case OrderStatus.Processed:
                        states.Add(OrderStatus.Opened);
                        states.Add(OrderStatus.Shipped);
                        states.Add(OrderStatus.Cancelled);
                        break;
                    case OrderStatus.Shipped:
                        break;
                    case OrderStatus.Cancelled:
                        break;
                }

            return states.AsReadOnly();
        }
	}
}